﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Rance
{
    public partial class Team : INotifyPropertyChanged
    {
        #region PropertyChange

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public string Member
        {
            get
            {
                var list = (from r in this.TeamRole
                            select r.Role);
                StringBuilder sb = new StringBuilder();
                foreach (var item in list)
                    sb.Append(string.Format("{0} ", item.Name));

                return sb.ToString();
            }
        }

        //private bool isInnerSetting = false;

        private Role _左军先锋;
        public Role 左军先锋
        {
            get
            {
                return _左军先锋;
            }
            set
            {
                if (_左军先锋 != value)
                {
                    _左军先锋 = value;
                    SendPropertyChanged("左军先锋");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军后卫, value))
                    //    左军后卫 = null;
                    //if (object.Equals(中军先锋, value))
                    //    中军先锋 = null;
                    //if (object.Equals(中军后卫, value))
                    //    中军后卫 = null;
                    //if (object.Equals(右军先锋, value))
                    //    右军先锋 = null;
                    //if (object.Equals(右军后卫, value))
                    //    右军后卫 = null;

                    //isInnerSetting = false;
                }
            }
        }

        private Role _左军后卫;
        public Role 左军后卫
        {
            get
            {
                return _左军后卫;
            }
            set
            {
                if (_左军后卫 != value)
                {
                    _左军后卫 = value;
                    SendPropertyChanged("左军后卫");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军先锋, value))
                    //    左军先锋 = null;
                    //if (object.Equals(中军先锋, value))
                    //    中军先锋 = null;
                    //if (object.Equals(中军后卫, value))
                    //    中军后卫 = null;
                    //if (object.Equals(右军先锋, value))
                    //    右军先锋 = null;
                    //if (object.Equals(右军后卫, value))
                    //    右军后卫 = null;

                    //isInnerSetting = false;
                }
            }
        }

        private Role _中军先锋;
        public Role 中军先锋
        {
            get
            {
                return _中军先锋;
            }
            set
            {
                if (_中军先锋 != value)
                {
                    _中军先锋 = value;
                    SendPropertyChanged("中军先锋");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军先锋, value))
                    //    左军先锋 = null;
                    //if (object.Equals(左军后卫, value))
                    //    左军后卫 = null;
                    //if (object.Equals(中军后卫, value))
                    //    中军后卫 = null;
                    //if (object.Equals(右军先锋, value))
                    //    右军先锋 = null;
                    // if (object.Equals(右军后卫, value))
                    //    右军后卫 = null;

                    //isInnerSetting = false;
                }
            }
        }

        private Role _中军后卫;
        public Role 中军后卫
        {
            get
            {
                return _中军后卫;
            }
            set
            {
                if (_中军后卫 != value)
                {
                    _中军后卫 = value;
                    SendPropertyChanged("中军后卫");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军先锋, value))
                    //    左军先锋 = null;
                    //if (object.Equals(左军后卫, value))
                    //    左军后卫 = null;
                    //if (object.Equals(中军先锋, value))
                    //    中军先锋 = null;
                    //  if (object.Equals(右军先锋, value))
                    //    右军先锋 = null;
                    //if (object.Equals(右军后卫, value))
                    //    右军后卫 = null;

                    //isInnerSetting = false;
                }
            }
        }

        private Role _右军先锋;
        public Role 右军先锋
        {
            get
            {
                return _右军先锋;
            }
            set
            {
                if (_右军先锋 != value)
                {
                    _右军先锋 = value;
                    SendPropertyChanged("右军先锋");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军先锋, value))
                    //    左军先锋 = null;
                    //if (object.Equals(左军后卫, value))
                    //    左军后卫 = null;
                    //if (object.Equals(中军先锋, value))
                    //    中军先锋 = null;
                    //if (object.Equals(中军后卫, value))
                    //    中军后卫 = null;
                    //if (object.Equals(右军后卫, value))
                    //    右军后卫 = null;

                    //isInnerSetting = false;
                }
            }
        }

        private Role _右军后卫;
        public Role 右军后卫
        {
            get
            {
                return _右军后卫;
            }
            set
            {
                if (_右军后卫 != value)
                {
                    _右军后卫 = value;
                    SendPropertyChanged("右军后卫");
                    //if (isInnerSetting)
                    //    return;
                    //isInnerSetting = true;

                    //if (object.Equals(左军先锋, value))
                    //    左军先锋 = null;
                    //if (object.Equals(左军后卫, value))
                    //    左军后卫 = null;
                    //if (object.Equals(中军先锋, value))
                    //    中军先锋 = null;
                    //if (object.Equals(中军后卫, value))
                    //    中军后卫 = null;
                    //if (object.Equals(右军先锋, value))
                    //    右军先锋 = null;

                    //isInnerSetting = false;
                }
            }
        }

        public override string ToString()
        {
            return Name;
        }
    }
}
